﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using Assets.Scripts.Editor;

[CustomEditor(typeof(ParameterManager))]
public class ParameterManagerEditor : Editor
{
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();
        ParameterManager manager = (ParameterManager)target;
        if (GUILayout.Button("Export CSV"))
        {
            var param = manager.DumpParams();
            string path = EditorUtility.SaveFilePanel("Save parameters to folder", "", "parameters", "csv");
            if (path == "" || path == null) return;
            CSVTool.Write(path, System.Text.Encoding.UTF8, param);
        }
        if (GUILayout.Button("Import CSV"))
        {
            string path = EditorUtility.OpenFilePanel("Load parameters from", "", "csv");
            if (path == "" || path == null) return;

            var param = CSVTool.Read(path, System.Text.Encoding.UTF8); 
            manager.LoadParams(param);
            
        }
    }
}
